package com.wobito.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wobito.common.constants.BaseResponse;
import com.wobito.common.constants.TableDataInfo;
import com.wobito.common.utils.ResultUtils;
import com.wobito.pojo.dto.borrow.BorrowDTO;
import com.wobito.pojo.vo.borrow.BorrowVO;
import com.wobito.service.IBorrowService;
import com.wobito.system.aspect.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Wangbaba
 * @Date 2024/8/29 14:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/manage/borrowOverview")
@Api(tags = "借阅情况总览")
public class BorrowManageController {

    @Autowired
    private IBorrowService borrowService;

    @GetMapping()
    @ApiOperation(value = "根据条件获取借阅情况总览")
    @OperLog(thing = "根据条件获取借阅情况总览")
    @PreAuthorize("hasAnyRole('SUPER_ADMIN','NOMAL_ADMIN')")
    public BaseResponse getBorrowOverList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "latId", required = false) Long latId,
                                          @RequestParam(value = "queryName", required = false) String queryName,
                                          @RequestParam(value = "status", required = false) Integer status) {
        TableDataInfo dataInfo = new TableDataInfo();
        PageHelper.startPage(pageNum, pageSize);
        List<BorrowDTO> borrowDTOS = borrowService.selectBorrowList(new BorrowVO(latId, queryName, status));
        dataInfo.setRows(borrowDTOS);
        dataInfo.setTotal(new PageInfo(borrowDTOS).getTotal());
        return ResultUtils.success(dataInfo);
    }

}
